package com.studycloud.controller;

import com.studycloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
/**
 * 订单 控制层
 * @author JP
 */
@RestController
@Slf4j
public class PaymentController
{
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private  String serverPort;

    @GetMapping(value = "/payment/hystrix/paymentinfo_ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id)
    {
        return paymentService.paymentInfo_OK(id);
    }

    @GetMapping(value = "/payment/hystrix/paymentinfo_no/{id}")
    public String paymentInfo_ON(@PathVariable("id") Integer id)
    {
        log.info(paymentService.paymentInfo_NO(id));
        return paymentService.paymentInfo_NO(id);
    }

    /**
     * 服务熔断
     * @param id
     * @return
     */
    @GetMapping("payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id)
    {
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("****result: "+result);
        return result;
    }

}
